//
//  BettingOppose.m
//  Gxj
//
//  Created by 💋索少杰 on 2017/10/20.
//  Copyright © 2017年 wkq. All rights reserved.
//

#import "BettingOppose.h"

@interface BettingOppose ()<UIScrollViewDelegate>

@property(nonatomic, strong)NSArray * arr;

#define Start_X          22.0f      // 第一个按钮的X坐标
#define Start_Y          0.0f     // 第一个按钮的Y坐标
#define Width_Space      20.0f      // 2个按钮之间的横间距
#define Height_Space     40.0f     // 竖间距
#define Button_Height   30.0f    // 高
#define Button_Width    75.0f    // 宽

@end

@implementation BettingOppose

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        [self addSubview:self.viewF];
        //滚动视图
        [self.viewF addSubview:self.scrollViewF];
        //文字
        [self.viewF addSubview:self.yazhuLabelF];
        [self.viewF addSubview:self.yazhuNumLabelF];
        //确定
        [self addSubview:self.determineF];
        
        
        //想点数量按钮
        
    _arr=@[@"5",@"10",@"15",@"20",@"25",@"30",@"35",@"40",@"45",@"50",@"55",@"60",@"65",@"70",@"75",@"80",@"85",@"90",@"95",@"100"];
        
        for (int i = 0 ; i < _arr.count; i++) {
            NSInteger index = i % 3;
            NSInteger page = i / 3;
            
            // 圆角按钮
            UIButton *mapBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
            
            mapBtn.tag = i+500;//这句话不写等于废了
            mapBtn.frame = CGRectMake(index * (Button_Width + Width_Space) + Start_X, page  * (Button_Height + Height_Space)+Start_Y, Button_Width, Button_Height);
            //[mapBtn setBackgroundImage:[UIImage imageNamed:arr[index]] forState:UIControlStateNormal];
            mapBtn.layer.borderWidth=1;
            mapBtn.layer.borderColor=[UIColor whiteColor].CGColor;
            mapBtn.layer.cornerRadius=kWidthScale(15);
            [mapBtn setTitle:[NSString stringWithFormat:@"%@",_arr[i]] forState:UIControlStateNormal];
            [mapBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            //[mapBtn setTitleColor:[UIColor colorWithRed:(162.0/255) green:(162.0/255) blue:(162.0/255) alpha:1] forState:UIControlStateSelected];
            //mapBtn.titleLabel.textAlignment=NSTextAlignmentCenter;
            mapBtn.titleLabel.font=[UIFont systemFontOfSize:kWidthScale(15)];
            
            [self.scrollViewF addSubview:mapBtn];
            //按钮点击方法
            [mapBtn addTarget:self action:@selector(mapBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        }
        
        [self setViewUp];
        
    }
    
    return self;
}

//点击按钮方法,这里容易犯错
-(void)mapBtnClick:(UIButton *)sender{
    //记住,这里不能写成"mapBtn.tag",这样你点击任何一个button,都只能获取到最后一个button的值,因为前边的按钮都被最后一个button给覆盖了
    
    for (int i = 0; i <= _arr.count; i++) {
        UIButton *btn = [self viewWithTag:i+500];

        if(btn.tag!=sender.tag){
            btn.backgroundColor=[UIColor clearColor];
//            btn.selected=NO;
            btn.enabled=YES;
        }else {
            
//            btn.layer.borderColor =[UIColor redColor].CGColor;
//            btn.layer.borderWidth=1;
            btn.backgroundColor=[UIColor colorWithRed:(162.0/255) green:(162.0/255) blue:(162.0/255) alpha:1];
            btn.enabled=YES;
        }
}
    

    
    //NSLog(@"%ld",sender.tag);
}
- (void)setViewUp
{
    //View
    _viewF.sd_layout
    .topSpaceToView(self, kHeightScale(304/2))
    .rightSpaceToView(self, kWidthScale(65/2))
    .leftSpaceToView(self, kWidthScale(65/2))
    .heightIs(kHeightScale(590/2));
    //文字
    _yazhuLabelF.sd_layout
    .topSpaceToView(self.viewF, kHeightScale(58/2))
    .leftSpaceToView(self.viewF, kWidthScale(60))
    .rightSpaceToView(self.viewF, kWidthScale(60))
    .autoHeightRatio(0);
    _yazhuNumLabelF.sd_layout
    .topSpaceToView(self.scrollViewF, kHeightScale(40/2))
    .leftSpaceToView(self.viewF, kWidthScale(190/2))
    .rightSpaceToView(self.viewF, kWidthScale(190/2))
    .autoHeightRatio(0);
    //滚动视图
    _scrollViewF.sd_layout
    .topSpaceToView(self.viewF, kHeightScale(144/2))
    .leftSpaceToView(self.viewF, 0)
    .rightSpaceToView(self.viewF, 0)
    .heightIs(kHeightScale(345/2));
    //确定
    _determineF.sd_layout
    .topSpaceToView(self.viewF, kHeightScale(25))
    .leftSpaceToView(self, kWidthScale(152/2))
    .rightSpaceToView(self, kWidthScale(152/2))
    .heightIs(kHeightScale(88/2));
    
    
    
}

- (UIView *)viewF
{
    if (!_viewF)
    {
        _viewF=[[UIView alloc] init];
        _viewF.layer.borderWidth=1;
        _viewF.layer.borderColor=[UIColor whiteColor].CGColor;
        _viewF.layer.masksToBounds=YES;
        _viewF.layer.cornerRadius=kWidthScale(20);
        
    }
    return _viewF;
}
//滚动视图
- (UIScrollView *)scrollViewF
{
    if (!_scrollViewF)
    {
        //滚动视图
        _scrollViewF=[[UIScrollView alloc] init];
        _scrollViewF.contentSize=CGSizeMake(self.viewF.frame.size.width, kHeightScale(460));
        _scrollViewF.delegate=self;
        //_scrollView.backgroundColor=[UIColor orangeColor];
        
    }
    return _scrollViewF;
}
//文字
- (UILabel *)yazhuLabelF
{
    if (!_yazhuLabelF)
    {
        _yazhuLabelF=[[UILabel alloc] init];
        _yazhuLabelF.text=@"您已选择代表反方进行辩论";
        _yazhuLabelF.textColor=[UIColor whiteColor];
        _yazhuLabelF.font=[UIFont systemFontOfSize:kWidthScale(15)];
        _yazhuLabelF.textAlignment=NSTextAlignmentCenter;
        //_yazhuLabel.backgroundColor=[UIColor yellowColor];
    }
    return _yazhuLabelF;
}
//文字
- (UILabel *)yazhuNumLabelF
{
    if (!_yazhuNumLabelF)
    {
        _yazhuNumLabelF=[[UILabel alloc] init];
        _yazhuNumLabelF.text=@"请选择押注想点数额";
        _yazhuNumLabelF.textColor=[UIColor whiteColor];
        _yazhuNumLabelF.font=[UIFont systemFontOfSize:kWidthScale(13)];
        _yazhuNumLabelF.textAlignment=NSTextAlignmentCenter;
        //_yazhuLabel.backgroundColor=[UIColor yellowColor];
    }
    return _yazhuNumLabelF;
}

//确定按钮
- (UIButton *)determineF
{
    if (!_determineF)
    {
        _determineF=[[UIButton alloc] init];
        _determineF.layer.borderWidth=1;
        _determineF.layer.borderColor=[UIColor whiteColor].CGColor;
        [_determineF setTitle:@"确定" forState:UIControlStateNormal];
        _determineF.titleLabel.font=[UIFont systemFontOfSize:kWidthScale(15)];
        _determineF.titleLabel.textAlignment=NSTextAlignmentCenter;
        _determineF.layer.masksToBounds=YES;
        _determineF.layer.cornerRadius=kWidthScale(20);
        
    }
    return _determineF;
}



@end
